using System.Collections;
using UnityEngine;

public class PlayerManager : MonoBehaviour
{
	public enum PlayerState
	{
		Game,
		Cutscene,
		NoPlayerMovement,
		Battle
	}

	public P_MovementBase _PMove;

	public P_InteractionManager _PInteract;

	public P_AnimationStateManager _PAnimation;

	public AudioSource PlayerAudioSource;

	public INT_Chat PlayerINT_Chat;

	public SpriteRenderer PlayerSpriteRenderer;

	public float _PlayerHealth = 160f;

	public float _PlayerMaxHealth = 160f;

	[Header("Game,Cutscene,NoPlayerMovement")]
	public PlayerState _PlayerState;

	private static PlayerManager instance;

	public static PlayerManager Instance => instance;

	private void Awake()
	{
		if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)this)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		instance = this;
		Object.DontDestroyOnLoad((Object)(object)instance);
	}

	private void Start()
	{
		Cursor.visible = false;
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)285) || Input.GetKeyDown((KeyCode)292))
		{
			Screen.fullScreen = !Screen.fullScreen;
			SettingsManager.Instance.SaveBoolSetting("Fullscreen", Screen.fullScreen);
		}
	}

	public void PlayerPrintDebugTest_One()
	{
		Debug.LogWarning((object)"One");
	}

	public void PlayerPrintDebugTest_Two()
	{
		Debug.LogWarning((object)"Two");
	}

	public void PlayerPrintDebugTest_Three()
	{
		Debug.LogWarning((object)"Three");
	}

	public void ResetToGameState()
	{
		_PlayerState = PlayerState.Game;
		if (_PMove.InDarkworld)
		{
			DarkworldMenu.Instance.CanOpenMenu = true;
			LightworldMenu.Instance.CanOpenMenu = false;
		}
		else
		{
			LightworldMenu.Instance.CanOpenMenu = true;
			DarkworldMenu.Instance.CanOpenMenu = false;
		}
	}

	public void ShakePlayer(float multiplier = 0.25f, float duration = 2f)
	{
		((MonoBehaviour)this).StartCoroutine(ShakeTarget(((Component)PlayerSpriteRenderer).transform, multiplier, duration));
	}

	private IEnumerator ShakeTarget(Transform target, float multiplier = 1f, float duration = 1f)
	{
		if ((Object)(object)target != (Object)null)
		{
			Vector3 originalPosition = target.position;
			float elapsedTime = 0f;
			PartyMemberSystem.Instance.SetAllPartyMembersFollowing(Following: false);
			PartyMemberSystem.Instance.SetAllPartyMemberStates(Susie_Follower.MemberFollowerStates.Disabled);
			while (multiplier > 0f && !((Object)(object)target == (Object)null))
			{
				float num = Random.Range(-1f, 1f) * multiplier;
				target.position = Vector2.op_Implicit(new Vector2(originalPosition.x + num, originalPosition.y));
				elapsedTime += Time.fixedDeltaTime;
				multiplier -= Time.fixedDeltaTime * (1f / duration);
				yield return null;
			}
			if ((Object)(object)target != (Object)null)
			{
				target.position = originalPosition;
			}
			PartyMemberSystem.Instance.SetAllPartyMembersFollowing(Following: true);
			PartyMemberSystem.Instance.SetAllPartyMemberStates(Susie_Follower.MemberFollowerStates.CopyingInputs);
		}
	}
}
